package com.tianzeculture.stagebao.net;

import com.tianzeculture.stagebao.bean.AliBean;
import com.tianzeculture.stagebao.bean.ArtistsDetailedBean;
import com.tianzeculture.stagebao.bean.AuthenticationBean;
import com.tianzeculture.stagebao.bean.ResultBean;
import com.tianzeculture.stagebao.bean.RongBean;
import com.tianzeculture.stagebao.bean.RongIdBean;
import com.tianzeculture.stagebao.bean.User;
import com.tianzeculture.stagebao.bean.VersionBean;
import com.tianzeculture.stagebao.bean.WechatBean;
import com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2;
import com.tianzeculture.stagebao.network.net.httpclient.NewCustomResponseHandler;
import com.tianzeculture.stagebao.network.util.MD5Util;
import com.tianzeculture.stagebao.util.Util;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录
 */
public class UserRestUsage extends AppBaseRestUsageV2 {

    private final String LOGIN = "/user/login.do";//登录
    private final String GETCODE = "/code/getRegisterMobileCode.do";//获取手机验证码
    private final String REGISTER = "/user/register.do";//注册
    private final String UPDATEUSERINFO = "/user/UpdateUserInfo.do";//完善用户信息
    private final String RESETPASSWORD = "/user/resetPassword.do";//重置密码
    private final String MYINFO = "/user/myInfo.do";//获取个人信息

    private final String UPDATE_PASSWORD = "/user/updatePassword.do";//修改密码
    private final String UPDATE_IPHONE_NUM = "/user/UpdateIphoneNum.do";//修改手机号
    private final String GET_TOKEN = "/rongCloud/getToken.do";//获取token
    private final String GET_USERINFO = "/rongCloud/getUserInfo.do";//获取信息
    private final String LOGIN_CHECK_OTHER = "/user/chekThirdParty.do";//判断三方登录
    private final String LOGIN_BY_OTHER = "/user/thirdPartyRegister.do";//三方登录绑定
    private final String PAY_ALIPAY = "/pay/aliPay.do";//支付宝
    private final String PAY_WXPAY = "/pay/wechatPay.do";//微信支付
    private final String PERSONAL_AUTHENTICATION = "/user/insertConfirm.do";//个人认证
    private final String GET_AUTHENTICATION = "/user/findConfirmById.do";//获取个人认证信息
    private final String GET_VERSION = "/version/getVersionInfo.do";//获取版本号和下载地址


    /**
     * 登录
     */
    public void login(int taskId, String iPhoneNumber, String pwd) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("iPhoneNumber", iPhoneNumber);
        paramMap.put("password", MD5Util.md5(pwd));
        post(LOGIN, Util.returnRealParam(paramMap), new NewCustomResponseHandler<User>(taskId) {
        }.setCallSuperRefreshUI(true));
    }


    /**
     * 获取验证码
     *
     * @param taskId
     * @param iPhoneNumber
     * @param type
     */
    public void getCode(int taskId, String iPhoneNumber, int type) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("iPhoneNumber", String.valueOf(iPhoneNumber));
        paramMap.put("type", String.valueOf(type));
        post(GETCODE, Util.returnRealParam(paramMap), new NewCustomResponseHandler<ResultBean>(taskId) {
        }.setCallSuperRefreshUI(true));
    }

    /**
     * 注册
     *
     * @param taskId
     * @param iPhoneNumber
     * @param code
     * @param pwd
     * @param userType
     */
    public void Register(int taskId, String iPhoneNumber, String code, String pwd, int userType) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("iPhoneNumber", String.valueOf(iPhoneNumber));
        paramMap.put("code", code);
        paramMap.put("password", MD5Util.md5(pwd));
        paramMap.put("userType", String.valueOf(userType));// 0表示艺人，1表示商家
        post(REGISTER, Util.returnRealParam(paramMap), new NewCustomResponseHandler<ResultBean>(taskId) {
        }.setCallSuperRefreshUI(true));
    }

    /**
     * 更新用户信息
     *
     * @param taskId
     * @param name
     * @param nickname
     * @param sex
     * @param address
     */
    public void updateUserInfo(int taskId, String imagUrl, String nickname, int sex, String address) {
        Map<String, String> paramMap = new HashMap<>();
//        paramMap.put("name", name);
        paramMap.put("photoImgFile", imagUrl);
        paramMap.put("nickname", nickname);
        paramMap.put("sex", String.valueOf(sex));
        paramMap.put("address", address);
        post(UPDATEUSERINFO, Util.returnRealParam(paramMap), new NewCustomResponseHandler<User>(taskId) {
        }.setCallSuperRefreshUI(true));
    }

    /**
     * 重置密码
     *
     * @param taskId
     * @param iPhoneNumber
     * @param code
     * @param password
     */
    public void resetPassword(int taskId, String iPhoneNumber, String code, String password) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("iPhoneNumber", iPhoneNumber);
        paramMap.put("code", code);
        paramMap.put("password", MD5Util.md5(password));
        post(RESETPASSWORD, Util.returnRealParam(paramMap), new NewCustomResponseHandler<ResultBean>(taskId) {
        }.setCallSuperRefreshUI(true));
    }

    /**
     * 获取用户信息
     *
     * @param taskId
     * @param userId
     */
    public void myInfo(int taskId, String userId) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        post(MYINFO, Util.returnRealParam(paramMap), new NewCustomResponseHandler<ArtistsDetailedBean>(taskId) {
        }.setCallSuperRefreshUI(true));
    }

    /**
     * 更新用户头像/公司简介
     *
     * @param taskId
     */
    public void updateUserInfo(int taskId, Map<String, String> params) {
        post(UPDATEUSERINFO, Util.returnRealParam(params), new NewCustomResponseHandler<Map<String, String>>(taskId) {
        });
    }

    /**
     * 更新用户信息
     *
     * @param taskId
     * @param user
     */
    public void updateUserInfo(int taskId, User user) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("name", user.getName());
        paramMap.put("nickname", user.getNickname());
        paramMap.put("sex", user.getSex());
        paramMap.put("address", user.getAddress());
        paramMap.put("industryId", user.getIndustry());
//        paramMap.put("alent", user.getAlent());
        post(UPDATEUSERINFO, Util.returnRealParam(paramMap), new NewCustomResponseHandler<Map<String, String>>(taskId) {
        });
    }

    /**
     * 修改密码
     *
     * @param taskId
     * @param oldPassword
     * @param newPassword
     */
    public void updatePassword(int taskId, String oldPassword, String newPassword) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("oldPassword", MD5Util.md5(oldPassword));
        paramMap.put("newPassword", MD5Util.md5(newPassword));
        post(UPDATE_PASSWORD, Util.returnRealParam(paramMap), new NewCustomResponseHandler<Map<String, String>>(taskId) {
        });
    }

    /**
     * 修改手机号
     *
     * @param taskId
     * @param iPhoneNumber
     * @param code
     */
    public void updateIphoneNum(int taskId, String iPhoneNumber, String code) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("iPhoneNumber", iPhoneNumber);
        paramMap.put("code", code);
        post(UPDATE_IPHONE_NUM, Util.returnRealParam(paramMap), new NewCustomResponseHandler<Map<String, String>>(taskId) {
        });
    }

    /**
     * 融云获取token
     *
     * @param taskId
     */
    public void getToken(int taskId, String userId) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        post(GET_TOKEN, Util.returnRealParam(paramMap), new NewCustomResponseHandler<RongIdBean>(taskId) {
        });
    }

    /**
     * 融云获取个人信息
     *
     * @param taskId
     */
    public void getUserInfo(int taskId, String userId) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("rid", userId);
        post(GET_USERINFO, Util.returnRealParam(paramMap), new NewCustomResponseHandler<RongBean>(taskId) {
        });
    }

    /**
     * 判断三方登录是否绑定过
     *
     * @param taskId
     */
    public void loginCheckOther(int taskId, Map<String, String> paramMap) {
        post(LOGIN_CHECK_OTHER, Util.returnRealParam(paramMap), new NewCustomResponseHandler<User>(taskId) {
        });
    }

    /**
     * 三方登录绑定
     *
     * @param taskId
     */
    public void loginByOther(int taskId, Map<String, String> paramMap) {
        post(LOGIN_BY_OTHER, Util.returnRealParam(paramMap), new NewCustomResponseHandler<User>(taskId) {
        });
    }

    /**
     * 支付宝支付
     *
     * @param taskId
     */
    public void payByAli(int taskId, String price) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("payNumber", price);
        post(PAY_ALIPAY, Util.returnRealParam(paramMap), new NewCustomResponseHandler<AliBean>(taskId) {
        });
    }

    /**
     * 微信支付
     *
     * @param taskId
     */
    public void payByWechat(int taskId, String price) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("payNumber", price);
        post(PAY_WXPAY, Util.returnRealParam(paramMap), new NewCustomResponseHandler<WechatBean>(taskId) {
        });
    }

    /**
     * 个人认证
     *
     * @param taskId
     */
    public void personalAuthentication(int taskId, Map<String, String> paramMap) {
        post(PERSONAL_AUTHENTICATION, Util.returnRealParam(paramMap), new NewCustomResponseHandler<WechatBean>(taskId) {
        });
    }

    /**
     * 获取个人认证信息
     *
     * @param taskId
     */
    public void getAuthentication(int taskId, Map<String, String> paramMap) {
        post(GET_AUTHENTICATION, Util.returnRealParam(paramMap), new NewCustomResponseHandler<AuthenticationBean>(taskId) {
        });
    }

    /**
     * 获取最新版本
     *
     * @param taskId
     */
    public void getVersion(int taskId, Map<String, String> paramMap) {
        post(GET_VERSION, Util.returnRealParam(paramMap), new NewCustomResponseHandler<VersionBean>(taskId) {
        });
    }

}